import { FieldConfig } from '@alilc/lowcode-types';
import { ITypeEntityField } from '../types';

export const checkFieldIsUnique = (fields: ITypeEntityField[] = []) => {
  const keys: Record<string, boolean> = {};
  for (let i = 0; i < fields.length; i++) {
    const field = fields[i];
    if (keys[field.name]) return false;
    keys[field.name] = true;
  }
  return true;
};

export const checkCommonFieldIsUnique = (fields: FieldConfig[] = []) => {
  const keys: Record<string, boolean> = {};
  for (let i = 0; i < fields.length; i++) {
    const field = fields[i];
    if (keys[field.name]) return false;
    keys[field.name] = true;
  }
  return true;
};
